package com.pk.android.view;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.pk.android.R;
import com.pk.android.model.BaseFragment;
import com.pk.android.view.adapter.LeagueTeamsAdapter;

public class AddTeamFragment extends BaseFragment {
 
	public static final String EXTRA_TITLE = "EXTRA_TITLE";
	
	LeagueTeamsAdapter teamsAdapter;
	Button btnAllLeagues;
	TextView leagueName;
	
	GetLeagueName mCallback;
	
	public interface GetLeagueName
	{
		public String getLeagueName();
		public boolean getIsLeagueCreated();
	}

	public static final AddTeamFragment newInstance(String title)
	{
		AddTeamFragment f = new AddTeamFragment();
		Bundle bdl = new Bundle(1);
	   bdl.putString(EXTRA_TITLE, title);
	   f.setArguments(bdl);

		return f;
	}
    
	@Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        
        // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception
        try {
        	mCallback = (GetLeagueName) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement GetLeagueName");
        }
    }
	
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
    	super.onCreateView(inflater, container, savedInstanceState);
    	
        view = inflater.inflate(R.layout.fragment_pk_add_team, container, false);
                
    	//((TextView)view.findViewById(R.id.txt_league_name)).setText(title);
        
        
        leagueName = (TextView)view.findViewById(R.id.txt_league_name);
        
        ChangeFooterState(false);
    	
        return view;
    }
    
	@Override
	public void setMenuVisibility(boolean menuVisible) {
		// TODO Auto-generated method stub
		super.setMenuVisibility(menuVisible);
		
		if(mCallback == null)
			return;
		
		if(menuVisible) 
			if(mCallback != null && mCallback.getIsLeagueCreated())
			{
				leagueName.setText(mCallback.getLeagueName());
				ChangeFooterState(true);
			}
			else
			{
				leagueName.setText("");
				ChangeFooterState(false);
			}
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.
		super.onCreate(savedInstanceState);
	}


	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}
	
	public void ChangeFooterState(boolean setEnabled)
	{
		((Button)view.findViewById(R.id.btn_add)).setEnabled(setEnabled);
        ((Button)view.findViewById(R.id.btn_cancel)).setEnabled(setEnabled);
	}
}
